package com.qfedu.dao;

import com.qfedu.pojo.entity.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface PermissionRepository extends JpaRepository<Permission, Integer> {
    @Query(value = "select perid from role_permission where roleid = ?1", nativeQuery = true)
    List<Integer> selectPerIdByRoleId(Integer id);

    @Query(value = "select DISTINCT p.permission_name from user u, user_role ur, role r, role_permission rp, permission p where u.id=ur.userid and ur.roleid=r.id and r.id=rp.roleid and rp.perid=p.id and u.user_name=?1", nativeQuery = true)
    List<String> selectPermissionByUserName(String userName);
}
